﻿using System;
using System.Collections.Generic;
using System.Windows;
using MyFloridaHouse.libSvOpenDistricts.MapShapes;
using MyFloridaHouse.libSvOpenDistricts.SummaryDataGrid;
using MyFloridaHouse.ServiceConn.DistrBldrSvcRef;

namespace MyFloridaHouse.libSvOpenDistricts.Districts
{
    public delegate void DistrictLabelDataChangedEventHandler(object sender, EventArgs e);

    public class DistrictLabel : RegionLabelBase
    {
        private bool _showDistrictsPopDev;
        public bool showDistrictsPopDev
        {
            get { return _showDistrictsPopDev; }
            set
            {
                if (_showDistrictsPopDev != value)
                {
                    _showDistrictsPopDev = value;
                    NotifyPropertyChanged("showDistrictsPopDev");
                    RaiseRegionLabelDataChanged();
                }
            }
        }

        public DistrictLabel(RegionLabelAppearance appearance, SummaryDataGridManager summaryDataGridManager)
        {
            this.appearance = appearance;
        }


        public void OnSummaryDataGridDataChanged(EventArgs args)
        {
            RaiseRegionLabelDataChanged();
        }
        public override UIElement BuildLabel(bool showName, string regionName, List<RegionDataDTO> regionDataList)
        {
            // district labels are shoe-horned into region label format
            // the regionName is the districtID, regionDataList is empty
            // having this districtLabel object lets us insert population deviation into the data list
            List<string> dataList = new List<string>();
            string nameLabel = string.Empty;
            if (showName) 
            {
                nameLabel = regionName; 
            }

            if (showDistrictsPopDev)
            {
                try
                {
                    int districtID = -1;
                    districtID = int.Parse(regionName);
                    dataList.Add(SummaryDataGridManager.GetPopulationDeviation(districtID).ToString());
                }
                catch
                {
                    //  error
                    dataList.Add(int.MaxValue.ToString());
                }
            }
            return GetRegionLabelShape(nameLabel, dataList);
        }
    }
}
